package com.axend.aerosense.common.adapter;

import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.axend.aerosense.common.R;
import com.axend.aerosense.common.base.IEventBaseContent;
import com.axend.aerosense.common.bean.AlarmBean;
import com.axend.aerosense.common.databinding.CommonEventItemTopBinding;
import com.axend.aerosense.common.util.DateUtil;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.axend.aerosense.common.bean.LogType;

import org.jetbrains.annotations.NotNull;

public class TopItemProvider extends BaseItemProvider<IEventBaseContent> {
    private CommonEventItemTopBinding viewDataBinding;

    @Override
    public void onViewHolderCreated(@NotNull BaseViewHolder viewHolder, int viewType) {
        super.onViewHolderCreated(viewHolder, viewType);
        // 绑定View
        viewDataBinding = DataBindingUtil.bind(viewHolder.itemView);
    }

    /**
     * 当 ViewHolder 创建完毕以后，会执行此回掉
     * 可以在这里做任何你想做的事情
     */

    @Override
    public int getItemViewType() {
        return 0;
    }

    @Override
    public int getLayoutId() {
        return R.layout.common_event_item_top;
    }

    @Override
    public void convert(@NotNull BaseViewHolder baseViewHolder, IEventBaseContent baseContent) {
        if (baseContent == null) {
            return;
        }
        viewDataBinding = baseViewHolder.getBinding();


        String title = baseContent.getEventTypeName();
        if(baseContent instanceof AlarmBean){
            title = title + baseViewHolder.itemView.getContext().getString(R.string.common_alarm);

            if(LogType.FALL_DOWN.getType() == baseContent.getEventType()){
                viewDataBinding.commonHistroyHeadImage.setImageResource(R.drawable.common_user_icon_fall);

            }else if(LogType.SLEEP_TIMEOUT.getType() == baseContent.getEventType()){
                viewDataBinding.commonHistroyHeadImage.setImageResource(R.drawable.common_sleeptimeout);

            }else if(LogType.INTRUDE.getType() == baseContent.getEventType()){
                viewDataBinding.commonHistroyHeadImage.setImageResource(R.drawable.common_intrusion);

            }else if(LogType.GO_OUT_NOT_BACK.getType() == baseContent.getEventType()){
                viewDataBinding.commonHistroyHeadImage.setImageResource(R.drawable.common_outdoor);

            }else if(LogType.ToiletDetention.getType() == baseContent.getEventType()){
                viewDataBinding.commonHistroyHeadImage.setImageResource(R.drawable.common_bathroom);

            }else if(LogType.NightNotBack.getType() == baseContent.getEventType()){
                viewDataBinding.commonHistroyHeadImage.setImageResource(R.drawable.common_getoutroom);

            }else if (LogType.StandingStill.getType() == baseContent.getEventType()){
                viewDataBinding.commonHistroyHeadImage.setImageResource(R.drawable.common_icon_motionless_alert);

            }else if (LogType.NoVitalSignals.getType() == baseContent.getEventType()){
                viewDataBinding.commonHistroyHeadImage.setImageResource(R.drawable.common_icon_no_vital_signals);

            }else if (LogType.BedExitWarning.getType() == baseContent.getEventType()){
                viewDataBinding.commonHistroyHeadImage.setImageResource(R.drawable.common_icon_bed_exit_warning);

            }else if (LogType.AbnormalSleep.getType() == baseContent.getEventType()){
                viewDataBinding.commonHistroyHeadImage.setImageResource(R.drawable.common_icon_abnormal_sleep);

            } else{
                viewDataBinding.commonHistroyHeadImage.setVisibility(View.GONE);
            }

            viewDataBinding.commonFirstWargingView.setBackgroundResource(R.drawable.common_warning_histroy_fall);
            viewDataBinding.commonEventName.setTextColor(viewDataBinding.commonEventName.getResources().getColor(R.color.common_alert_text_red, null));

        }else{
            viewDataBinding.commonHistroyHeadImage.setVisibility(View.GONE);
            viewDataBinding.commonFirstWargingView.setBackgroundResource(R.drawable.common_round_rectangle_yellow_5);
            viewDataBinding.commonEventName.setTextColor(viewDataBinding.commonEventName.getResources().getColor(R.color.common_e_top_txt, null));
        }

        viewDataBinding.commonEventName.setText(title);

        // 获取 Binding
        viewDataBinding.commonEventName.setText(baseContent.getEventTypeName());
        viewDataBinding.commonHistroyRoom.setText(baseContent.getEventRoomName());
        viewDataBinding.commonHistroyTime.setText(DateUtil.getStringDateJudgeToday(baseContent.getEventTime()));


    }
}
